{extend name="Base" /}
{block name="title"}{$title}{/block}
{block name="body"}
<legend>发送邀请</legend>
<div class="am-form am-u-lg-6 am-u-lg-centered am-u-md-6 am-u-md-centered am-u-sm-12 am-u-sm-centered" data-am-validator>
	<fieldset>
		<div class="am-form-group am-input-group">
			<span class="am-input-group-label"><i class="am-icon-envelope am-icon-fw"></i></span>
			<input type="text" class="am-form-field" name="email" placeholder="有效期7天" pattern="^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}$" required/>
			<span class="am-input-group-btn">
			<button class="am-btn am-btn-default am-center submit" type="button" onclick="submit()">发送</button>
			</span>
		</div>
	</fieldset>
</div>
<hr/>
<table class="am-table am-table-striped am-table-hover">
	<thead>
	<tr>
		<th class="am-text-middle am-text-nowrap am-show-md-up">ID</th>
		<th class="am-text-middle am-text-nowrap">邀请码</th>
		<th class="am-text-middle am-text-nowrap am-show-md-up">发送时间</th>
		<th class="am-text-middle am-text-nowrap">使用者</th>
	</tr>
	</thead>
	<tbody>
	{volist name="info" id="u"}
	<tr>
		<td class="am-text-middle am-text-nowrap am-show-md-up">{$u.id}</td>
		{php}if ($u['softdel'] == 0) {{/php}
		<td class="am-text-middle am-text-nowrap"><span class="am-badge am-radius am-badge-primary">{$u.invitecode}</span></td>
		{php}} else {{/php}
		<td class="am-text-middle am-text-nowrap"><span class="am-badge am-radius am-badge-success">{$u.invitecode}</span></td>
		{php}}{/php}
		<td class="am-text-middle am-text-nowrap am-show-md-up">{$u.addtime}</td>
		<td class="am-text-middle am-text-nowrap">{$u.username}</td>
	</tr>
	{/volist}
	</tbody>
</table>

<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
	<div class="am-modal-dialog">
		<div class="am-modal-hd">错误</div>
		<div class="am-modal-bd">邮件发送失败</div>
		<div class="am-modal-footer">
			<span class="am-modal-btn">知道了</span>
		</div>
	</div>
</div>

<script>
	function submit() {
		var data = {
			email: $("input[name=email]").val()
		};

		$.ajax({
			type: "POST",
			url: "/index/users/doSendInvite",
			cache: false,
			data: data,
			dataType: "json",
			success: function (data) {
				if (data.status === 0) {
					if (data.message) {
						$(".am-modal-bd").html(data.message);
					}
					$("#my-alert").modal();
				} else if (data.status === 1) {
					$(".am-modal-bd").html(data.message);
					$("#my-alert").modal();
					$(".am-modal-btn").click(function () {
						location.href = "/index/users/sendinvite";
					});
				} else {
					$(".am-modal-bd").html("系统故障，请稍候再试");
					$("#my-alert").modal();
				}
			}
		});
	}

	document.onkeydown = keyDownSearch;
	function keyDownSearch(e) {
		if (!e) e = window.event;
		if ((e.keyCode || e.which) === 13) {
			submit();
		}
	}
</script>
{/block}